﻿CREATE PROCEDURE [dbo].[sp_Sys_SaveProduct]
	@ID INT,
	@ProductName nvarchar(100), 
	@Size nvarchar(50),
	@Color nvarchar(50),
	@OperatorID INT,
	@OperatorName nvarchar(50)
AS
	-- 插入操作
	IF(@ID = NULL)
	Insert Product(ProductName, Size, Color, CreateOn, CreateBy, CreateByName, UpdateOn, UpdateBy, UpdateByName)
	Values(@ProdcutName, @Size, @Color, GETDATE(), @OperatorID, @OperatorName, GETDATE(), @OperatorID, @OperatorName)
	-- 更新操作
	Else
	Begin
		If not exists (Select * From Product Where ID = @ID)
		Begin
			RAISERROR 2000 'sp_Sys_SaveProduct:指定的ID值不存在'
			Return
		End
		Update Product
		Set ProductName = @ProductName
		,Size = @Size
		,Color = @Color
		,UpdateOn = GETDATE()
		,UpdateBy = @OperatorID
		,UpdateByName = @OperatorName
		Where ID = @ID
	End
RETURN 0